import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useTagsStore = defineStore(
    'tags',
    () => {
        let tagsMenuList = ref([
            {
                icon: "HomeFilled",
                name: "数据总览",
                isLink: "",
                isHide: false,
                isFull: false,
                isAffix: true,
                isKeepAlive: true,
                path: '/dashboard'
            }
        ])
        function addTagsItem(tagItem) {
            if (tagsMenuList.value.every(item => item.path !== tagItem.path)) {
                tagsMenuList.value.push(tagItem)
            }
        }
        function delTagsItem(item) {
            tagsMenuList.value = tagsMenuList.value.filter(tag => tag.path != item)
        }

        //关闭标签
        function closeMultipleTab(tabsMenuValue) {
            tagsMenuList.value = tagsMenuList.value.filter(item => {
                return item.path === tabsMenuValue || item.isAffix;
            });
        }

        return { tagsMenuList, addTagsItem, delTagsItem,closeMultipleTab }
    },
    {
        persist: true
    }
)